#!/usr/bin/env python
# -*- coding: UTF-8 -*-


class HashFileReaderError(Exception):
    def __init__(self, message):
        Exception.__init__(self, message)

class HashFileReader:
    def __init__(self, name = "CHECKSUMS"):
        self.__name = name

    def read(self):
        result = {}

        fd = None
        try:
            fd = file(self.__name, "r")
            lines = fd.readlines()
            for line in lines:
                [value,key] = line.split("\t")
                str = key[:len(key)-1] #used to get out of \n in the end of line. Because writelines() does not add line separators.
                result[str] = value
                
        except Exception, error:
            raise HashFileReaderError(error.message)
        finally:
            if fd: fd.close()
            
        return result